import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import sun.applet.Main;

import com.dao.CategroryDao;
import com.user.Category;


public class CategroryServlet extends HttpServlet {

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;utf-8");
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		CategroryDao dao = new CategroryDao();
	
		try {
			List<Category> list = dao.getAll();
			HttpSession session = request.getSession();
			session.setAttribute("dataall", list);
			//request.setAttribute("dataall", list);
			request.getRequestDispatcher("/productClass.jsp").forward(request, response);
			for(int t=0;t<list.size();t++){
				Category category = list.get(t);
				//System.out.println("--"+category.getEpc_name());
				
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}

	public static void main(String[] args) {
		CategroryDao dao = new CategroryDao();
		int a = 0;
		int page = 0;
		int pageCount = 10;
		try {
			 a = dao.getCount();
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(a != 0){
			if(a/pageCount==0){
				page = a/pageCount;
			}else{
				page = a/pageCount+1;
			}
		}
		try {
			List<Category> lis = dao.getAnyByPage(page, pageCount);
			for(int i=0;i<lis.size();i++){
				Category category = lis.get(i);
				System.out.println(category.getEpc_name());
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			doGet(request, response);
	}

}
